package com.halflife.comeElectricity.admin;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/3/24 0024.
 */
public class DateUtil {
    /**
     * 日期字符串转时间戳
     * @param dateStr
     * @param
     * @return
     */
    public static Long transForMilliSecondByTim(String dateStr){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date date =null;
        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date == null ? null : transForMilliSecond(date);
    }
    public static String getTimeCode(){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
        Date date =null;
        return sdf.format(new Date());
    }

    /**
     * 日期字符串转时间戳
     * @param dateStr
     * @param
     * @return
     */
    public static Long transForMilliSecondByTim_(String dateStr){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date =null;
        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date == null ? null : transForMilliSecond(date);
    }
    /**
     * 日期转时间戳
     * @param date
     * @return
     */
    public static Long transForMilliSecond(Date date){
        if(date==null) return null;
        return (Long)(date.getTime());
    }
}
